home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
rotise12.zip
/
REPORT.C
< prev
next >
Wrap
Text File
|
1993-03-28
|
36KB
|
1,249 lines
/* report.c
Jonathan Arnold 1991
Routines to generate the final report.
report - main routine
*/
#include <string.h>
#include "rotise.h"
#include "rdb.h"
/* External data referenced */
extern RDB_TEAM *RotoTeams; /* roster.c - First team in list */
extern char LeagueName[];
extern int Weeks; /* stenog.c */
/* Local data publicly available */
BOOL Use_IBM_Chars = FALSE; /* whether to use extended IBM char set */
/* Private function prototypes */
void crunch_rotise PROTO( (void) );
void batter_out PROTO( (FILE *outfp, RDB_TEAM *team, int wsF ) );
void pitcher_out PROTO( (FILE *outfp, RDB_TEAM *team, int wsF ) );
void print_batstat PROTO( (FILE *outfp, int slotN, char *name, char *team, char *sal,
char *con, char *wk1, PDBT_BATTER *batP, PDBT_BATTER *wkbP) );
void print_pchstat PROTO( (FILE *outfp, int slotN, char *name, char *team, char *salstr,
char *con, char *wk1, PDBT_PITCHER *pchP, PDBT_PITCHER *wkpP) );
void do_standings PROTO( (FILE *outfp) );
void print_standings PROTO( (FILE *outfp) );
void print_wstandings PROTO( (FILE *outfp) );
void crunch_batter PROTO( (RDB_TEAM*team) );
void crunch_pitcher PROTO( (RDB_TEAM*team) );
void print_bathdr PROTO( (FILE *) );
static RDB_PLAYER *next_player PROTO( ( RDB_TEAM *teamP, RDB_PLAYER *playerP ) );
static freeprint PROTO( (PDB_PNAME *) );
/* Private data */
static FILE *FlfP;
static UWORD Flposmask;
static char *Flpos;
static char *Flposdesc;
static int FlposC;
/* Generate freelist */
void freelist ARGLIST( (flfname) )
FARG( char *flfname )
{
if ( ( FlfP = fopen( flfname, "w" ) ) == NULL )
{ /* Can't open freelist file */
fprintf( stderr, "freelist: can't open file \"%s\"\n", flfname );
return;
}
for ( Flposmask = 0x0001; ;Flposmask <<= 1 )
{ /* Do all different positions */
Flpos = mask_to_pos( Flposmask );
if ( Flpos == NULL )
{ /* Mask of 0 will be the "catch-all" position */
Flposmask = 0;
Flposdesc = "Unknown";
}
else
Flposdesc = mask_to_posdesc( Flposmask );
FlposC = 0;
pdb_walk( freeprint );
if ( Flpos == NULL )
{ /* All done with positional lists */
break;
}
}
fclose( FlfP );
}
/* Freelist output routine */
static int
freeprint ARGLIST( ( pnameP ) )
FARG( PDB_PNAME *pnameP )
{
UWORD pos; /* Player's position mask */
PDB_PNAME fullname; /* Player's full name */
PDATA *pdataP; /* Player data */
PDBT_BATTER batblk; /* Batter data */
PDBT_PITCHER pchblk; /* Pitcher data */
char rptname[50]; /* Buffer for name */
if ( pnameP == NULL )
{
if ( FlposC == 0 )
fprintf( FlfP, "%s: None eligible.\n", Flposdesc );
fprintf( FlfP, "\n\n\n\n" );
return ( TRUE );
}
if ( !pdb_getpos( pnameP, &pos ) )
{ /* Can't get position for player -- this shouldn't happen. */
fprintf( stderr, "freeprint: can't get positions for %s %s!\n",
&pnameP->pn_fname[0], &pnameP->pn_lname[0] );
return ( TRUE );
}
pdataP = pdb_pdata( &pnameP->pn_lname[0], &pnameP->pn_fname[0],
pnameP->batter );
if ( pdataP == NULL )
{ /* This shouldn't happen either. */
fprintf( stderr, "freeprint: can't get player status.\n" );
return ( FALSE );
}
if ( pdataP->zorch != PLAYER_FREE )
return ( TRUE );
if ( ( Flposmask == 0 ) && ( pos != 0 ) )
{ /* Mask of 0 is for "other" free players (w/o positions) */
return ( TRUE );
}
else if ( ( Flposmask != 0 ) && ( ( pos & Flposmask ) == 0 ) )
{ /* Not valid at this position */
return ( TRUE );
}
if ( FlposC++ == 0 )
{ /* First guy this position? */
fprintf( FlfP, "%s\n", Flposdesc );
fprintf( FlfP, "-----------------------------------\n" );
}
pdb_name( pnameP, Weeks, &fullname );
sprintf( &rptname[0], "%s, %s",
&fullname.pn_lname[0], &fullname.pn_fname[0] );
fprintf( FlfP, "%-15s %3s ", &rptname[0], &fullname.pn_team[0] );
/* Now print current year's stats for this guy */
if ( Flposmask == POS_P )
{ /* Do pitcher stats */
if ( !pdb_pitchstats( pnameP, 0, Weeks, &pchblk ) )
fprintf( FlfP, "<stats unavailable>" );
else
{
fprintf( FlfP, "%2dW %2dS %5.2fERA %5.2fRatio %3d.%dIP %3dER %3dH %3dBB",
pchblk.ps_won, pchblk.ps_saved,
era( &pchblk ), ratio( &pchblk ),
pchblk.ps_outs/3, pchblk.ps_outs%3,
pchblk.ps_er, pchblk.ps_hits, pchblk.ps_bb
);
}
}
else if ( Flposmask != 0 )
{ /* Do batter stats */
if ( !pdb_batstats( pnameP, 0, Weeks, &batblk ) )
fprintf( FlfP, "<stats unavailable>" );
else
{
fprintf( FlfP, "%.3fAvg (%3d/%-3d) %2dHR %3dBI %3dSB",
avg( &batblk ), batblk.bs_hits, batblk.bs_atbat,
batblk.bs_hr, batblk.bs_rbi, batblk.bs_sb );
}
}
if ( strlen( pdataP->status ) > 0 )
{ /* some kind of status */
if ( strcmp( pdataP->status, WAIVED_STRING ) == 0 && pdataP->week != Weeks )
{ /* too long ago, clear status */
pdataP->status[0] = '\0';
}
else
{
if ( Flposmask == POS_P )
fprintf( FlfP, "\n " );
fprintf( FlfP, " **** %s on %s ****", pdataP->status, pdataP->date );
}
}
fprintf( FlfP, "\n" );
return ( TRUE );
}
/* Generate worksheet file */
void worksheet ARGLIST( (fnameP) )
FARG( char *fnameP )
{
FILE *wfP;
RDB_TEAM *teams;
if ( ( wfP = fopen( fnameP, "w" ) ) == NULL )
{
fprintf( stderr, "worksheet: can not open file \"%s\"\n", fnameP );
return;
}
crunch_rotise();
for ( teams = RotoTeams; teams != NULL; teams = teams->next )
{ /* print each team worksheet */
fprintf( wfP, "%*s%s\n", 50- (strlen(LeagueName)/2), " ", LeagueName );
batter_out( wfP, teams, TRUE );
fprintf( wfP, "\n");
pitcher_out( wfP, teams, TRUE );
/* send a form feed */
printf( "%c", 0x0C );
}
fclose( wfP );
}
void report NOARGLIST
{
RDB_TEAM *teams;
crunch_rotise();
for ( teams = RotoTeams; teams != NULL; teams = teams->next )
{ /* print each team stats */
fprintf( stdout, "%*s%s\n", 50-(strlen(LeagueName)/2), " ", LeagueName );
batter_out( stdout, teams, FALSE );
fprintf( stdout, "\n");
pitcher_out( stdout, teams, FALSE );
/* send a form feed */
printf( "%c", 0x0C );
}
do_standings( stdout );
/* Print histograms */
printf( "\n\n Ordered rankings year to date -- year/week\n\n" );
standings();
print_histogram( stdout, FALSE );
printf( "\n\n\n\n Ordered rankings week %d -- week/year\n\n", Weeks );
wk_standings();
print_histogram( stdout, TRUE );
}
/* Simple routine to draw dividing line, which is done quite often */
void draw_divider ARGLIST( (outfp) )
FARG( FILE *outfp )
{
if ( !Use_IBM_Chars )
fprintf( outfp, "\n-----------------------------------------------------------+--------------------");
else
fprintf( outfp, "\n───────────────────────────────────────────────────────────┼────────────────────");
}
/*
void batter_out( FILE *outfp, RDB_TEAM *team, int wsF )
Print out the complete and weekly stats for all batters on the active roster as of
the final week in data.
ACCEPTS:
FILE *outfp - FILE to output report to
RDB_TEAM *team - Rotisserie team to report about
wsF - TRUE if making a worksheet, FALSE otherwise.
RETURNS:
Nothing
*/
void batter_out ARGLIST( (outfp, team, wsF) )
NFARG( FILE *outfp )
NFARG( RDB_TEAM *team )
FARG( int wsF )
{
PDBT_BATTER batblk, weekblk;
RDB_PLAYER *player;
PDB_PNAME pname;
BOOL done_reserved;
PDATA *pdata;
char salstr[10], week1str[10];
/* Init week */
team->bweek.bs_atbat = team->bweek.bs_hits =
team->bweek.bs_1b = team->bweek.bs_2b =
team->bweek.bs_3b = team->bweek.bs_hr =
team->bweek.bs_bb = team->bweek.bs_hpb =
team->bweek.bs_rbi = team->bweek.bs_sb =
team->bweek.bs_cs = 0;
fprintf( outfp, "=== %s ===", team->name );
fprintf( outfp, "\tGM: %s\n", team->owner );
print_bathdr( outfp );
for ( player = NULL; ; )
{
/* Find next player in slot-order */
player = next_player( team, player );
if ( player == NULL )
break;
if ( slot_get( player->slot )->slot[0] == 'P' )
{ /* check for active batters */
continue;
}
if ( (player->status != STATUS_ACTIVE && player->end != Weeks) ||
(player->status == STATUS_ACTIVE && player->start > Weeks) )
{ /* either old player or brand new player - not important */
continue;
}
/* Read from start to current week for active players */
if ( !pdb_batstats( &player->pname, player->start-1,
Weeks, &batblk ))
{ /* can't find player in database! */
batblk.bs_atbat = batblk.bs_hits =
batblk.bs_1b = batblk.bs_2b =
batblk.bs_3b = batblk.bs_hr =
batblk.bs_bb = batblk.bs_hpb =
batblk.bs_rbi = batblk.bs_sb =
batblk.bs_cs = 0;
}
sprintf( salstr, "$%3.1f0", (float)player->salary/10.0 );
sprintf( week1str, "%2d", player->start-1 );
if ( !pdb_name( &player->pname, Weeks, &pname ) )
{ /* couldn't find it, init */
strcpy( pname.pn_team, "---" );
}
#ifdef OLD_REPORT
print_batstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk, NULL, NULL );
#endif
/* Now print stat for current week */
if ( !pdb_batstats( &player->pname, Weeks-1, Weeks, &weekblk ))
{ /* can't find player in database! */
weekblk.bs_atbat = weekblk.bs_hits =
weekblk.bs_1b = weekblk.bs_2b =
weekblk.bs_3b = weekblk.bs_hr =
weekblk.bs_bb = weekblk.bs_hpb =
weekblk.bs_rbi = weekblk.bs_sb =
weekblk.bs_cs = 0;
}
#ifdef OLD_REPORT
print_batstat( outfp, "", " Week:",
"", " ", " ", " ", &weekblk, NULL, NULL );
#else
pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, TRUE );
if ( pdata == NULL || pdata->status[0] == '\0' ||
strcmp( pdata->status, WAIVED_STRING ) == 0 )
{ /* no status or WAIVED by team, so print weekly stats */
print_batstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
&weekblk );
}
else
{ /* no weekly stuff, cuz we are going to show status instead */
print_batstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
NULL );
fprintf( outfp, "****%s on %s****", pdata->status, pdata->date );
}
#endif
/* Total up week stats */
team->bweek.bs_atbat += weekblk.bs_atbat;
team->bweek.bs_hits += weekblk.bs_hits;
team->bweek.bs_1b += weekblk.bs_1b;
team->bweek.bs_2b += weekblk.bs_2b;
team->bweek.bs_3b += weekblk.bs_3b;
team->bweek.bs_hr += weekblk.bs_hr;
team->bweek.bs_bb += weekblk.bs_bb;
team->bweek.bs_hpb += weekblk.bs_hpb;
team->bweek.bs_rbi += weekblk.bs_rbi;
team->bweek.bs_sb += weekblk.bs_sb;
team->bweek.bs_cs += weekblk.bs_cs;
}
/* print out old other stats */
/* First show reserved players */
draw_divider( outfp );
done_reserved = FALSE;
for ( player = team->players; player != NULL; player = player->next )
{ /* print out each reserved player's data */
if ( slot_get( player->slot )->slot[0] == 'P' )
{ /* checking for batters */
continue;
}
if ( (player->status != STATUS_RESERVE) ||
(player->status == STATUS_RESERVE && player->end == Weeks) )
{ /* either not on reserved, or just reserved this week */
continue;
}
/* Read from start to current week for active players */
if ( !pdb_batstats( &player->pname, player->start-1,
player->end, &batblk ))
{ /* can't find player in database! */
batblk.bs_atbat = batblk.bs_hits =
batblk.bs_1b = batblk.bs_2b =
batblk.bs_3b = batblk.bs_hr =
batblk.bs_bb = batblk.bs_hpb =
batblk.bs_rbi = batblk.bs_sb =
batblk.bs_cs = 0;
}
sprintf( salstr, "$%3.1f0", (float)player->salary/10.0 );
sprintf( week1str, "%2d", player->start-1 );
if ( !pdb_name( &player->pname, Weeks, &pname ) )
{ /* couldn't find it, init */
strcpy( pname.pn_team, "---" );
}
if ( !done_reserved )
{ /* draw reserved header */
fprintf( outfp, "\n%-59s%1s%-15s", "RESERVED", (Use_IBM_Chars?"│":"|"), " Status" );
draw_divider( outfp );
done_reserved = TRUE;
}
print_batstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
NULL );
/* Now add status */
pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, TRUE );
if ( pdata != NULL )
fprintf( outfp, "%5s %s %5s", pdata->status, (strlen(pdata->date)?"on":""), pdata->date );
}
/* now for the rest */
print_batstat( outfp, 99, "All others", "", "", "", "", &team->oldb, NULL );
draw_divider( outfp );
/* now, print team totals for batters */
print_batstat( outfp, 99, "TOTALS:", "", "", "","", &team->batters , &team->bweek);
if ( !Use_IBM_Chars )
fprintf( outfp, "\n-----------------------------------------------------------+--------------------");
else
fprintf( outfp, "\n───────────────────────────────────────────────────────────┴────────────────────");
#ifdef OLD_REPORT
print_batstat( outfp, "", "Week Totals:", "", "", "", "", &team->bweek , NULL);
#endif
}
/*
void pitcher_out( FILE *outfp, RDB_TEAM *team, int wsF )
Print out the complete and weekly stats for all pitchers on the active roster as of
the final week in data.
ACCEPTS:
FILE *outfp - FILE to output report to
RDB_TEAM *team - Rotisserie team to report about
wsF - TRUE if making a worksheet, FALSE otherwise
RETURNS:
Nothing
*/
void pitcher_out ARGLIST( (outfp, team, wsF) )
NFARG( FILE *outfp )
NFARG( RDB_TEAM *team )
FARG( int wsF )
{
PDBT_PITCHER pchblk, weekblk;
RDB_PLAYER *player;
PDB_PNAME pname;
PDATA *pdata;
char salstr[10], week1str[10];
BOOL done_reserved;
/* Clear the week totals */
team->pweek.ps_outs = team->pweek.ps_er = team->pweek.ps_bb = team->pweek.ps_hits =
team->pweek.ps_won = team->pweek.ps_lost = team->pweek.ps_saved = 0;
#ifdef OLD_REPORT
print_pchstat( outfp, "POS", " Name", "Team", " Sal", "C", "WK1", (PDB_PITCHER *)NULL );
#else
print_pchstat( outfp, 99, NULL, NULL, NULL, NULL, NULL, (PDB_PITCHER *)NULL, NULL );
#endif
for ( player = NULL; ; )
{
/* Find next player in slot-order */
player = next_player( team, player );
if ( player == NULL )
break;
if ( slot_get( player->slot)->slot[0] != 'P' )
{ /* Bypass non-pitchers */
continue;
}
if ( (player->status != STATUS_ACTIVE && player->end != Weeks) ||
(player->status == STATUS_ACTIVE && player->start > Weeks) )
{ /* either old player or brand new player - not important */
continue;
}
/* Get and print total stats for player */
if ( !pdb_pitchstats( &player->pname, player->start-1,
Weeks, &pchblk ))
{ /* can't find it! */
pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
pchblk.ps_won = pchblk.ps_lost = pchblk.ps_saved = 0;
}
sprintf( salstr, "$%3.1f0", (float)player->salary / 10.0 );
sprintf( week1str, "%2d", player->start-1 );
if ( !pdb_name( &player->pname, Weeks, &pname ) )
{ /* couldn't find it, init */
strcpy( pname.pn_team, "---" );
}
#ifdef OLD_REPORT
print_pchstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ),
week1str, &pchblk );
#endif
/* Now do week */
if ( !pdb_pitchstats( &player->pname, Weeks-1,
Weeks, &weekblk ))
{ /* can't find it! */
weekblk.ps_outs = weekblk.ps_er = weekblk.ps_bb = weekblk.ps_hits =
weekblk.ps_won = weekblk.ps_lost = weekblk.ps_saved = 0;
}
#ifdef OLD_REPORT
print_pchstat( outfp, "", " Week",
"", "", "","",&pchblk );
#else
pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, FALSE );
if ( pdata == NULL || pdata->status[0] == '\0' ||
strcmp( pdata->status, WAIVED_STRING ) == 0 )
{ /* no status, or WAIVED by team, so print week stats */
print_pchstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ),
week1str, &pchblk, &weekblk );
}
else
{ /* no weekly stuff, cuz we are going to show status instead */
print_pchstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ),
week1str, &pchblk, NULL );
fprintf( outfp, "****%s on %s****", pdata->status, pdata->date );
}
#endif
/* Add in week's totals */
team->pweek.ps_outs += weekblk.ps_outs;
team->pweek.ps_er += weekblk.ps_er;
team->pweek.ps_bb += weekblk.ps_bb;
team->pweek.ps_hits += weekblk.ps_hits;
team->pweek.ps_won += weekblk.ps_won ;
team->pweek.ps_lost += weekblk.ps_lost;
team->pweek.ps_saved += weekblk.ps_saved;
}
/* now for rest of team */
/* First show reserved players */
draw_divider( outfp );
done_reserved = FALSE;
for ( player = team->players; player != NULL; player = player->next )
{ /* print each player who is a pitcher */
if ( slot_get( player->slot)->slot[0] != 'P' )
{ /* Bypass non-pitchers */
continue;
}
if ( (player->status != STATUS_RESERVE) ||
(player->status == STATUS_RESERVE && player->end == Weeks) )
{ /* either not on reserved, or just reserved this week */
continue;
}
/* Get and print total stats for player */
if ( !pdb_pitchstats( &player->pname, player->start-1,
player->end, &pchblk ))
{ /* can't find it! */
pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
pchblk.ps_won = pchblk.ps_lost = pchblk.ps_saved = 0;
}
sprintf( salstr, "$%3.1f0", (float)player->salary / 10.0 );
sprintf( week1str, "%2d", player->start-1 );
if ( !pdb_name( &player->pname, Weeks, &pname ) )
{ /* couldn't find it, init */
strcpy( pname.pn_team, "---" );
}
if ( !done_reserved )
{ /* draw reserved header */
fprintf( outfp, "\n%-59s%1s%-15s", "RESERVED", (Use_IBM_Chars?"│":"|"), " Status" );
draw_divider( outfp );
done_reserved = TRUE;
}
print_pchstat( outfp, player->slot, player->name,
pname.pn_team, salstr, contract_string( player->contract ),
week1str, &pchblk, NULL );
/* Now add status */
pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, FALSE );
if ( pdata != NULL )
fprintf( outfp, "%5s %s %5s", pdata->status, (strlen(pdata->date)?"on":""), pdata->date );
}
/* now for the rest */
print_pchstat( outfp, 99, "All others", "", "", "", "", &team->oldp, NULL );
draw_divider( outfp );
/* and now show totals */
print_pchstat( outfp, 99, "TOTALS:", "","","", "", &team->pitchers, &team->pweek );
if ( !Use_IBM_Chars )
fprintf( outfp, "\n-----------------------------------------------------------+--------------------\n");
else
fprintf( outfp, "\n───────────────────────────────────────────────────────────┴────────────────────\n");
#ifdef OLD_REPORT
print_pchstat( outfp, "", "Week Totals:", "","","", "", &team->pweek );
fprintf( outfp, "\n" );
#endif
}
#ifdef OLD_REPORT
void print_batstat ARGLIST( (outfp, pos, name, team, sal, con, wk1, batP, wkbP) )
NFARG( FILE *outfp )
NFARG( char *pos )
NFARG( char *name )
NFARG( char *team )
NFARG( char *sal )
NFARG( char *con )
NFARG( char *wk1 )
NFARG( PDBT_BATTER *batP )
FARG( PDBT_BATTER *wkbP )
{
if ( batP == NULL )
{ /* NULL means print the header */
fprintf( outfp,"%3s %-20s%-4s %-4s%1s %3s%4s %4s %4s %3s %3s %3s %3s %3s %3s\n",
pos, name, team, sal, con, wk1,
"Avg", "AB", "H", "1B", "2B", "3B", "HR", "RBI", "SB"
);
return;
}
/* Print the batter stats */
fprintf( outfp, "%3s %-20s%-4s %-5s%1s %2s %.3f %4d %4d %4d %3d %3d %3d %3d %3d\n",
pos, name, team, sal, con, wk1,
avg( batP ),
batP->bs_atbat, batP->bs_hits,
batP->bs_1b, batP->bs_2b, batP->bs_3b, batP->bs_hr,
batP->bs_rbi, batP->bs_sb
);
}
void print_pchstat ARGLIST( (outfp, pos, name, team, salstr, pchP) )
NFARG( FILE *outfp )
NFARG( char *pos )
NFARG( char *name )
NFARG( char *team )
NFARG( char *salstr )
NFARG( char *con )
NFARG( char *wk1 )
FARG( PDBT_PITCHER *pchP )
{
if ( pchP == NULL )
{ /* NULL means print the header */
fprintf( outfp,"%3s %-18s%-4s %-5s%1s %3s %4s %2s %2s %2s %3s %3s %3s %4s %6s\n",
pos, name, team, salstr, con, wk1,
"IP", "W", "L", "SV",
"ER", "H", "BB", "ERA", "Ratio"
);
return;
}
/* Print the pitcher stats */
fprintf( outfp, "%3s %-18s%-4s %-5s%1s %2s %4d.%d %2d %2d %2d %3d %4d %3d %5.2f %6.3f\n",
pos, name, team, salstr, con, wk1,
pchP->ps_outs/3, pchP->ps_outs%3,
pchP->ps_won,
pchP->ps_lost,
pchP->ps_saved,
pchP->ps_er,
pchP->ps_hits,
pchP->ps_bb,
era( pchP ),
ratio( pchP )
);
}
#else
void print_bathdr ARGLIST( (outfp) )
FARG( FILE *outfp )
{
if ( !Use_IBM_Chars )
fprintf( outfp, "-----------------------------------------------------------+--------------------\n");
else
fprintf( outfp, "───────────────────────────────────────────────────────────┬────────────────────\n");
fprintf( outfp, "%-19s%-40s%1s%-18s\n", "BATTING", " Year to date", (Use_IBM_Chars?"│":"|"),
" This Week" );
fprintf( outfp, "%-19s%-3s %-3s %5s%1s %3s %4s %3s %3s %3s %4s%1s %2s %2s %2s %2s %2s %4s",
" Name", "Pos", "Tm", "Sal ", "C", "AB", "H", "HR", "RBI", "SB", "Avg", (Use_IBM_Chars?"│":"|"),
"AB", "H", "HR", "BI", "SB", "Avg" );
draw_divider( outfp );
}
void print_batstat ARGLIST( (outfp, slot, name, team, sal, con, wk1, batP, wkbP) )
NFARG( FILE *outfp )
NFARG( int slot )
NFARG( char *name )
NFARG( char *team )
NFARG( char *sal )
NFARG( char *con )
NFARG( char *wk1 )
NFARG( PDBT_BATTER *batP )
FARG( PDBT_BATTER *wkbP )
{
RDB_SLOT *slotP;
char *pos;
if ( slot == 99 )
{ /* This is for blank position. */
pos = "";
}
else
{
slotP = slot_get( slot );
if ( slotP == NULL )
pos = "";
else
pos = slotP->slot;
}
fprintf(outfp,"\n");
fprintf( outfp, "%-19.19s%-3s %-3s %5s%1s%4d %4d %3d %3d %3d .%03d%1s",
name, pos, team, sal, con,
batP->bs_atbat, batP->bs_hits,
batP->bs_hr, batP->bs_rbi, batP->bs_sb,
(int) (avg( batP )*1000.0), (Use_IBM_Chars?"│":"|") );
if ( wkbP != NULL )
{ /* print out weekly stats */
fprintf( outfp, "%3d%3d%3d%3d%3d .%03d",
wkbP->bs_atbat, wkbP->bs_hits, wkbP->bs_hr, wkbP->bs_rbi, wkbP->bs_sb,
(int) (avg( wkbP )*1000.0)
);
}
}
void print_pchstat ARGLIST( (outfp, slot, name, team, salstr,
con, wk1, pchP, wkpP) )
NFARG( FILE *outfp )
NFARG( int slot )
NFARG( char *name )
NFARG( char *team )
NFARG( char *salstr )
NFARG( char *con )
NFARG( char *wk1 )
NFARG( PDBT_PITCHER *pchP )
FARG( PDBT_PITCHER *wkpP )
{
float rat, er;
#ifdef USE_POS
RDB_SLOT *slotP;
char *pos;
if ( slot == 99 )
{ /* This is for blank position. */
pos = "";
}
else
{
slotP = slot_get( slot );
if ( slotP == NULL )
pos = "";
else
pos = slotP->slot;
}
#endif
if ( pchP == NULL )
{ /* NULL means print the header */
if ( !Use_IBM_Chars )
fprintf( outfp, "-----------------------------------------------------------+--------------------\n");
else
fprintf( outfp, "───────────────────────────────────────────────────────────┬────────────────────\n");
fprintf( outfp, "%-19s%-40s%1s%-18s\n", "PITCHING", " Year to date", (Use_IBM_Chars?"│":"|"),
" This Week" );
fprintf( outfp, "%-15s %3s %5s%1s%3s %3s %6s %4s %3s %4s%5s%1s%2s %2s%5s %4s%5s",
" Name", "Tm", "Sal ", "C", "W", "S", "IP ", "H ", "BB", "Rat.", "ERA",
(Use_IBM_Chars?"│":"|"), "W", "S", "IP", "Rat.", "ERA" );
draw_divider( outfp );
}
else
{ /* Print the pitcher stats */
rat = ratio( pchP );
er = era( pchP );
fprintf( outfp, "\n%-15.15s %3s %5s%1s%3d %3d %4d.%1d %4d %3d ",
name, team, salstr, con,
pchP->ps_won,
pchP->ps_saved,
pchP->ps_outs/3, pchP->ps_outs%3,
pchP->ps_hits,
pchP->ps_bb
);
if ( rat >= 100.0 )
{ /* just overflow it */
fprintf( outfp, "****" );
}
else
fprintf( outfp, "%4.2f", rat );
if ( er >= 100.0 )
fprintf( outfp, " ****" );
else
fprintf( outfp, "%5.2f", er );
fprintf( outfp, "%1s", (Use_IBM_Chars?"│":"|") );
if ( wkpP != NULL )
{ /* print out weekly stats */
fprintf( outfp, "%2d %2d%3d.%1d",
wkpP->ps_won,
wkpP->ps_saved,
wkpP->ps_outs/3, wkpP->ps_outs%3
);
rat = ratio( wkpP );
er = era( wkpP );
if ( rat >= 100.0 )
{ /* just overflow it */
fprintf( outfp, "****" );
}
else
fprintf( outfp, "%5.2f", rat );
if ( er >= 100.0 )
fprintf( outfp, " ****" );
else
fprintf( outfp, "%5.2f", er );
}
}
}
#endif /* OLD_REPORT */
void do_standings ARGLIST( (outfp) )
FARG( FILE *outfp )
{
/* Go ahead and generate the standings */
print_standings( outfp );
/* Form Feed */
fprintf( outfp, "%c", 0x0C );
/* And now the weekly ones */
print_wstandings( outfp );
/* Form Feed */
fprintf( outfp, "%c", 0x0C );
}
/* Do the total standings */
void print_standings ARGLIST( (outfp) )
FARG( FILE *outfp )
{
int kk, tt;
int tcnt;
RDB_TEAM *team;
RDB_TEAM *teams[MAX_TEAMS]; /* Sorted */
for( tcnt = 0, team = RotoTeams; team != NULL; team = team->next, tcnt++ )
{ /* Get sorted team list */
for( kk = 0; kk < tcnt; ++kk )
{ /* Find where this team goes */
if ( team->totalPnts > teams[kk]->totalPnts )
{
break;
}
}
for ( tt = tcnt; tt > kk; tt-- )
{ /* shuffle lower placed teams down one */
teams[tt] = teams[tt-1];
}
teams[kk] = team;
}
fprintf( outfp, "\n\n ==== %s ====\n", LeagueName );
fprintf( outfp, " ------>> Week: %d <<------\n\n", Weeks );
for( kk = 0; kk < tcnt; ++kk )
{ /* Print the standings */
fprintf( outfp, "%15s%-25.25s %4.1f\n", " ",
teams[kk]->name, teams[kk]->totalPnts );
}
fprintf( outfp, "\n\n" );
/* Print batter points */
fprintf( outfp, "%25s %4s %4s %4s %4s %4s %4s %4s %4s\n",
" TEAM ",
"Avg.", "Pts.",
"HR", "Pts.",
"RBI", "Pts.",
"SB", "Pts."
);
for( kk = 0; kk < tcnt; ++kk )
{ /* Print batter points */
team = teams[kk];
fprintf( outfp,
"%25s %4.3f %4.1f %4d %4.1f %4d %4.1f %4d %4.1f\n",
team->name,
avg( &team->batters ), team->points[RANK_AVG],
team->batters.bs_hr, team->points[RANK_HR],
team->batters.bs_rbi, team->points[RANK_RBI],
team->batters.bs_sb, team->points[RANK_SB]
);
}
fprintf( outfp, "\n%25s %4s %4s %5s %4s %7s %4s %5s %4s\n",
" TEAM ",
"Wins", "Pts.",
"Saves", "Pts.",
"ERA ", "Pts.",
"Ratio", "Pts."
);
for( kk = 0; kk < tcnt; ++kk )
{ /* Print pitcher points */
team = teams[kk];
fprintf( outfp,
"%25s %4d %4.1f %5d %4.1f %7.3f %4.1f %5.3f %4.1f\n",
team->name,
team->pitchers.ps_won, team->points[RANK_WINS],
team->pitchers.ps_saved, team->points[RANK_SVS],
era( &team->pitchers ), team->points[RANK_ERA],
ratio( &team->pitchers ), team->points[RANK_RATIO]
);
}
}
/* Do the weekly standings */
void print_wstandings ARGLIST( (outfp) )
FARG( FILE *outfp )
{
int kk, tt;
int tcnt;
RDB_TEAM *team;
RDB_TEAM *teams[MAX_TEAMS]; /* Sorted */
wk_standings();
for( tcnt = 0, team = RotoTeams; team != NULL; team = team->next, tcnt++ )
{ /* Get sorted team list */
for( kk = 0; kk < tcnt; ++kk )
{ /* Find where this team goes */
if ( team->totalPnts > teams[kk]->totalPnts )
{
break;
}
}
for ( tt = tcnt; tt > kk; tt-- )
{ /* shuffle lower placed teams down one */
teams[tt] = teams[tt-1];
}
teams[kk] = team;
}
fprintf( outfp, "\n\nWeek %d Single Week Standings:\n\n", Weeks );
for( kk = 0; kk < tcnt; ++kk )
{ /* Print the standings */
fprintf( outfp, "%15s%-25.25s %4.1f\n", " ",
teams[kk]->name, teams[kk]->totalPnts );
}
fprintf( outfp, "\n\n" );
/* Print batter points */
fprintf( outfp, "%25s %4s %4s %4s %4s %4s %4s %4s %4s\n",
" TEAM ",
"Avg.", "Pts.",
"HR", "Pts.",
"RBI", "Pts.",
"SB", "Pts."
);
for( kk = 0; kk < tcnt; ++kk )
{ /* Print batter points */
team = teams[kk];
fprintf( outfp,
"%25s %4.3f %4.1f %4d %4.1f %4d %4.1f %4d %4.1f\n",
team->name,
avg( &team->bweek ), team->points[RANK_AVG],
team->bweek.bs_hr, team->points[RANK_HR],
team->bweek.bs_rbi, team->points[RANK_RBI],
team->bweek.bs_sb, team->points[RANK_SB]
);
}
fprintf( outfp, "\n%25s %4s %4s %5s %4s %7s %4s %5s %4s\n",
" TEAM ",
"Wins", "Pts.",
"Saves", "Pts.",
"ERA ", "Pts.",
"Ratio", "Pts."
);
for( kk = 0; kk < tcnt; ++kk )
{ /* Print pitcher points */
team = teams[kk];
fprintf( outfp,
"%25s %4d %4.1f %5d %4.1f %7.3f %4.1f %5.3f %4.1f\n",
team->name,
team->pweek.ps_won, team->points[RANK_WINS],
team->pweek.ps_saved, team->points[RANK_SVS],
era( &team->pweek ), team->points[RANK_ERA],
ratio( &team->pweek ), team->points[RANK_RATIO]
);
}
}
/* crunch_rotise()
* run through all the teams, doing totals and weekly tallys.
* Also, make up the new standings.
*/
void crunch_rotise NOARGLIST
{
RDB_TEAM *team;
for ( team = RotoTeams; team != NULL; team = team->next )
{ /* crunch all the teams */
crunch_batter( team );
crunch_pitcher( team );
}
standings();
}
/* get totals and old stats for a team */
void crunch_batter ARGLIST( (team) )
FARG( RDB_TEAM *team )
{
PDBT_BATTER batblk;
RDB_PLAYER *player;
/* start totals off at zero */
team->batters.bs_atbat = team->batters.bs_hits = team->batters.bs_1b =
team->batters.bs_2b = team->batters.bs_3b =
team->batters.bs_hr = team->batters.bs_bb = team->batters.bs_hpb =
team->batters.bs_rbi = team->batters.bs_sb = team->batters.bs_cs = 0;
team->oldb.bs_atbat = team->oldb.bs_hits = team->oldb.bs_1b =
team->oldb.bs_2b = team->oldb.bs_3b = team->oldb.bs_hr =
team->oldb.bs_bb = team->oldb.bs_hpb = team->oldb.bs_rbi =
team->oldb.bs_sb = team->oldb.bs_cs = 0;
for ( player = team->players; player != NULL; player = player->next )
{ /* print out each player's data */
if ( slot_get( player->slot )->slot[0] != 'P' )
{ /* get batters for totalling */
if ( player->status == STATUS_MINORS )
{ /* don't even bother with this player */
continue;
}
/* Read from start to Weeks for active players, or end for inactive
ones. Make sure we don't go too far tho */
if ( !pdb_batstats( &player->pname, player->start-1,
(player->status == STATUS_ACTIVE ? Weeks :
(player->end < Weeks? player->end : Weeks)),
&batblk ))
{ /* can't find player in database, so just zero it! */
batblk.bs_atbat = batblk.bs_hits = batblk.bs_1b =
batblk.bs_2b = batblk.bs_3b = batblk.bs_hr =
batblk.bs_bb = batblk.bs_hpb = batblk.bs_rbi =
batblk.bs_sb = batblk.bs_cs = 0;
}
if ( player->start < Weeks &&
player->end < Weeks &&
player->status != STATUS_ACTIVE &&
player->status != STATUS_RESERVE )
{ /* total up 'old', non-reserved, batters */
team->oldb.bs_atbat += batblk.bs_atbat;
team->oldb.bs_hits += batblk.bs_hits;
team->oldb.bs_1b += batblk.bs_1b;
team->oldb.bs_2b += batblk.bs_2b;
team->oldb.bs_3b += batblk.bs_3b;
team->oldb.bs_hr += batblk.bs_hr;
team->oldb.bs_bb += batblk.bs_bb;
team->oldb.bs_hpb += batblk.bs_hpb;
team->oldb.bs_rbi += batblk.bs_rbi;
team->oldb.bs_sb += batblk.bs_sb;
team->oldb.bs_cs += batblk.bs_cs;
}
if ( player->start <= Weeks )
{ /* add in totals */
team->batters.bs_atbat += batblk.bs_atbat;
team->batters.bs_hits += batblk.bs_hits;
team->batters.bs_1b += batblk.bs_1b;
team->batters.bs_2b += batblk.bs_2b;
team->batters.bs_3b += batblk.bs_3b;
team->batters.bs_hr += batblk.bs_hr;
team->batters.bs_bb += batblk.bs_bb;
team->batters.bs_hpb += batblk.bs_hpb;
team->batters.bs_rbi += batblk.bs_rbi;
team->batters.bs_sb += batblk.bs_sb;
team->batters.bs_cs += batblk.bs_cs;
}
}
}
}
void crunch_pitcher ARGLIST( (team) )
FARG( RDB_TEAM *team )
{
PDBT_PITCHER pchblk;
RDB_PLAYER *player;
team->pitchers.ps_outs = team->pitchers.ps_er = team->pitchers.ps_bb = team->pitchers.ps_hits =
team->pitchers.ps_won = team->pitchers.ps_lost = team->pitchers.ps_saved = 0;
team->oldp.ps_outs = team->oldp.ps_er = team->oldp.ps_bb = team->oldp.ps_hits =
team->oldp.ps_won = team->oldp.ps_lost = team->oldp.ps_saved = 0;
for ( player = team->players; player != NULL; player = player->next )
{ /* print each player who is a pitcher */
if ( slot_get( player->slot )->slot[0] == 'P' )
{ /* either active or old pitcher */
if ( player->status == STATUS_MINORS )
{ /* don't bother with minor leaguers */
continue;
}
/* Read from start to Weeks for active players, or end for inactive
ones. Make sure we don't go too far tho */
if ( !pdb_pitchstats( &player->pname, player->start-1,
(player->status == STATUS_ACTIVE ? Weeks :
(player->end < Weeks? player->end : Weeks)),
&pchblk ))
{ /* can't find it, so zero and use it! */
pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
pchblk.ps_won = pchblk.ps_lost = pchblk.ps_saved = 0;
}
if ( player->start < Weeks &&
player->end < Weeks &&
player->status != STATUS_ACTIVE &&
player->status != STATUS_RESERVE )
{ /* just count the old stuff */
team->oldp.ps_outs += pchblk.ps_outs;
team->oldp.ps_er += pchblk.ps_er;
team->oldp.ps_bb += pchblk.ps_bb;
team->oldp.ps_hits += pchblk.ps_hits;
team->oldp.ps_won += pchblk.ps_won ;
team->oldp.ps_lost += pchblk.ps_lost;
team->oldp.ps_saved += pchblk.ps_saved;
}
if ( player->start <= Weeks )
{ /* tally up playing players */
team->pitchers.ps_outs += pchblk.ps_outs;
team->pitchers.ps_er += pchblk.ps_er;
team->pitchers.ps_bb += pchblk.ps_bb;
team->pitchers.ps_hits += pchblk.ps_hits;
team->pitchers.ps_won += pchblk.ps_won ;
team->pitchers.ps_lost += pchblk.ps_lost;
team->pitchers.ps_saved += pchblk.ps_saved;
}
}
}
}
/* Fetch next player in slot order. */
static RDB_PLAYER *next_player ARGLIST( ( teamP, playerP ) )
NFARG( RDB_TEAM *teamP )
FARG( RDB_PLAYER *playerP )
{
int slotN; /* Slot number looking for */
RDB_PLAYER *lowP; /* Ptr to lowest seen */
/* If any current player, see if there's another with equal slot.
Can happen with special expansion slots or with invalid slots. */
if ( playerP != NULL )
{
slotN = playerP->slot;
for( playerP = playerP->next; playerP != NULL; playerP = playerP->next )
{
if ( playerP->slot == slotN )
{ /* Matching slot; we'll take this one. */
return ( playerP );
}
}
}
else
{ /* No last player; look for lowest slot. */
slotN = -2; /* Slot must be greater than this. */
}
for ( lowP = NULL, playerP = teamP->players; playerP != NULL;
playerP = playerP->next )
{
if ( playerP->slot <= slotN )
{ /* Can't take this one. */
continue;
}
if ( lowP == NULL )
{ /* First valid one seen; remember it. */
lowP = playerP;
}
else if ( playerP->slot < lowP->slot )
{ /* This one's better. */
lowP = playerP;
}
}
/* Return whatever we found. */
return ( lowP );
}